﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Configuration;
using System.Configuration;

namespace Common
{
    public class SqlConnonString
    {
        static Configuration config = WebConfigurationManager.OpenWebConfiguration("~");
        public static void Update(string key, string value)
        {
            AppSettingsSection app = config.AppSettings;
            app.Settings[key].Value = value;
            config.Save(ConfigurationSaveMode.Modified);
        }

        public static string source = ConfigurationManager.AppSettings["DataSource"];
        public static string InitialCatalog = ConfigurationManager.AppSettings["InitialCatalog"];
        public static string UID = ConfigurationManager.AppSettings["UID"];
        public static string Pwd = ConfigurationManager.AppSettings["Pwd"];
        public static int ConnType = int.Parse(ConfigurationManager.AppSettings["ConnType"]);
        public static string GetsqlconStr()
        {
            string str = string.Empty;
            if (ConnType==0)
            {
                str = "server=" + source + ";database=" + InitialCatalog + ";uid=" + UID + ";pwd=" + Pwd + "";
            }
            else
            {
                str = "Server=" + source + ";Database=" + InitialCatalog + ";Trusted_Connection=True";
            }
           

            return str;
        }

        public static string sqlconn = SqlConnonString.GetsqlconStr();
    }
}